// electron/service/LoggerService.ts
import { loggerRepository } from '../repository/LoggerRepository';

type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';

class LoggerService {
  isValidLevel(level: string): level is LogLevel {
    return ['error', 'warn', 'info', 'verbose', 'debug', 'silly'].includes(
      level,
    );
  }

  log(level: string, ...args: any[]) {
    if (this.isValidLevel(level)) {
      loggerRepository.write(level, ...args);
    } else {
      loggerRepository.warnInvalid(level, ...args);
    }
  }

  handleError(error: any) {
    loggerRepository.logError(error);
  }

  cleanupMessage() {
    loggerRepository.info('日志IPC处理器已清理');
  }
}

export const loggerService = new LoggerService();
